package com.tjcd.project.library_base.room.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.tjcd.project.library_base.room.bean.UserBean;

import java.util.List;

import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Single;


/**
 * @Author jiangKunKun
 * @CreateDate 2022/2/21
 * @Description
 * @SpittingGrooves
 */
@Dao
public interface UserDao {
    /**
     * 查询全部
     * @return
     */
    @Query("SELECT * FROM " + UserBean.USER_TABLE_NAME)
    Flowable<List<UserBean>> queryUserAll();

//    public static void main(String[] args) {
//        new UserDao().queryUserAll().subscribeOn()
//                .observeOn()
//                .subscribe(new Consumer<List<UserBean>>() {
//                    @Override
//                    public void accept(List<UserBean> userBeans) throws Throwable {
//
//                    }
//                }, throwable -> {
//
//                });
//    }

    /**
     * 人脸id查询
     * @param name 用户姓名
     * @return
     */
    @Query("SELECT * FROM "+ UserBean.USER_TABLE_NAME + " WHERE "+
            "name" + " = :name")
    Single<UserBean> queryFaceId(String name);

    /**
     * 用户id 和 头像 查询
     * @param userId 用户id
     * @param name 用户姓名
     * @return
     */
    @Query("SELECT * FROM "+ UserBean.USER_TABLE_NAME + " WHERE "+
            "userId" + " = :userId" + " AND " + "name" + " = :name")
    UserBean queryUserId(String userId, String name);

    /**
     * 修改
     * @param userBeans 修改的人员集合
     * @return
     */
    @Update
    void updateUsers(List<UserBean> userBeans);

    /**
     * 添加
     * @param userBeans 添加人员集合
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertUserAll(List<UserBean> userBeans);

    /**
     * 删除
     * @param userBean 删除人员集合
     */
    @Delete
    void deleteUserBean(UserBean userBean);
}
